package highTech.javaBean;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

public class IntroSpectorTest {
	public static void main(String[] args) throws Exception{
		ReflectBean fb=new ReflectBean(3,5);
		String propertyName="x";
		
		PropertyDescriptor pd1=new PropertyDescriptor(propertyName, fb.getClass());
		Method methodGetx=pd1.getReadMethod();
		Object retVal=methodGetx.invoke(fb);
		System.out.println(retVal);
		
		Method methodSetx=pd1.getWriteMethod();
		methodSetx.invoke(fb, 7);
		System.out.println(fb.getX());
		
		BeanInfo beanInfo=Introspector.getBeanInfo(fb.getClass());
		PropertyDescriptor[] propertyArray=beanInfo.getPropertyDescriptors();
		for(PropertyDescriptor propertyD:propertyArray){
			if(propertyD.getName().equals(propertyName)){
				methodGetx=propertyD.getReadMethod();
				System.out.println(methodGetx.invoke(fb));
				break;
			}
		}
	}
}
